﻿using strange.extensions.command.impl;
using System;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 游戏胜利
/// </summary>
public class GameSuccessedCommand:EventCommand
{
    [Inject]
    public IntegrationModel IntegrationModel { get; set; }
    [Inject]
    public CardModel CardModel { get; set; }
    [Inject]
    public RoundModel RoundModel { get; set; }
    public override void Execute()
    {
        GameOverAgrs e = evt.data as GameOverAgrs;
        #region 更新积分
        if (e.PlayerWin)
        {
            IntegrationModel.PlayerIntegration += IntegrationModel.Results;
        }
        else
        {
            IntegrationModel.PlayerIntegration -= IntegrationModel.Results;
        }
        if (e.ComputerLeftWin)
        {
            IntegrationModel.ComputerLeftIntegration += IntegrationModel.Results;
        }
        else
        {
            IntegrationModel.ComputerLeftIntegration -= IntegrationModel.Results;
        }
        if (e.ComputerRightWIn)
        {
            IntegrationModel.ComputerRightIntegration += IntegrationModel.Results;
        }
        else
        {
            IntegrationModel.ComputerRightIntegration -= IntegrationModel.Results;
        }
        switch (e.Loader)
        {
            case CharacterType.Player:
                if (e.PlayerWin)
                {
                    IntegrationModel.PlayerIntegration += IntegrationModel.Results;
                }
                else
                {
                    IntegrationModel.PlayerIntegration -= IntegrationModel.Results;
                }
                break;
            case CharacterType.ComputerLeft:
                if (e.ComputerLeftWin)
                {
                    IntegrationModel.ComputerLeftIntegration += IntegrationModel.Results;
                }
                else
                {
                    IntegrationModel.ComputerLeftIntegration -= IntegrationModel.Results;
                }
                break;
            case CharacterType.ComputerRight:
                if (e.ComputerRightWIn)
                {
                    IntegrationModel.ComputerRightIntegration += IntegrationModel.Results;
                }
                else
                {
                    IntegrationModel.ComputerRightIntegration -= IntegrationModel.Results;
                }
                break;
        }
        #endregion
 
        #region 保存积分
        GameData data = new GameData()
        { PlayerIntegration = IntegrationModel.PlayerIntegration,
        ComputerLeftIntegration = IntegrationModel.ComputerLeftIntegration,
        ComputerRightIntegration = IntegrationModel.ComputerRightIntegration
        };
        Tools.SaveDate(data);
        #endregion
        //隐藏所有卡牌
        PoolManager._Instance.HideAllObject("CardUI");
        //初始化牌库
        CardModel.InitCardLibrary();
        //初始化回合
        RoundModel.InitRound();
        //更新到结束面板
        Tools.CreateUIPanel(PanelType.GameOverPanel);
        dispatcher.Dispatch(ViewEvent.GameSuccessed, data);
    }
}

